package logic

import (
	"context"
	"errors"
	"github.com/google/uuid"
	"shop/model/mysql"

	"shop/internal/svc"
	"shop/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReservationAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewReservationAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReservationAddLogic {
	return &ReservationAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ReservationAddLogic) ReservationAdd(in *shop.ReservationAddRequest) (*shop.ReservationAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error
	var r mysql.Reservation
	r.UserId = in.UserId
	r.ReservationSn = uuid.NewString()
	r.ReservationTime = in.ReservationTime
	r.HouseId = in.HouseId
	if err = r.Create(); err != nil {
		logx.Error("预约失败")
		return nil, errors.New("预约失败")
	}
	return &shop.ReservationAddResponse{
		Sn: r.ReservationSn,
		Id: int64(r.ID),
	}, nil
}
